package org.hk.kg.finance.student.action;

import java.io.File;
import java.util.Map;

import org.hk.kg.TraceObject;
import org.hk.kg.finance.FinanceConstants;
import org.hk.kg.ui.KGUiContext;
import org.hk.kg.ui.ParamsStack;
import org.hk.kg.utils.Constants;
import org.hk.kg.utils.LocalResouce;
import org.hk.kg.utils.StringUtils;


public class NewStudentAction extends BaseStudentAction {
	public TraceObject doSave(ParamsStack params)
	{
		Map rlt = params.getSimpleParams();
		
		//chargement begin
		if(!rlt.containsKey("studentId")||StringUtils.isEmpty("" + rlt.get("studentId")))
		{
			KGUiContext.instance.error(Constants.COMMON_FAIL_WINDOW_TITLE, FinanceConstants.MSG_STUID_EMPTY);
			return new TraceObject(None);
		}
		if(!rlt.containsKey("studentName")||StringUtils.isEmpty("" + rlt.get("studentName")))
		{
			KGUiContext.instance.error(Constants.COMMON_FAIL_WINDOW_TITLE, FinanceConstants.MSG_STUNAME_EMPTY);
			return new TraceObject(None);
		}
		if(!rlt.containsKey("studentSex")||StringUtils.isEmpty("" + rlt.get("studentSex")))
		{
			KGUiContext.instance.error(Constants.COMMON_FAIL_WINDOW_TITLE, FinanceConstants.MSG_STUSEX_EMPTY);
			return new TraceObject(None);
		}
		if(!rlt.containsKey("birthDate")||StringUtils.isEmpty("" + rlt.get("birthDate")))
		{
			KGUiContext.instance.error(Constants.COMMON_FAIL_WINDOW_TITLE, FinanceConstants.MSG_STUBIRTH_EMPTY);
			return new TraceObject(None);
		}
		if(!rlt.containsKey("stuClz")||StringUtils.isEmpty("" + rlt.get("stuClz")))
		{
			KGUiContext.instance.error(Constants.COMMON_FAIL_WINDOW_TITLE, FinanceConstants.MSG_STUCLZ_EMPTY);
			return new TraceObject(None);
		}
		if(!rlt.containsKey("stuType")||StringUtils.isEmpty("" + rlt.get("stuType")))
		{
			KGUiContext.instance.error(Constants.COMMON_FAIL_WINDOW_TITLE, FinanceConstants.MSG_STUTYPE_EMPTY);
			return new TraceObject(None);
		}
		//chargement end
		if(!rlt.containsKey("enterDate")||StringUtils.isEmpty("" + rlt.get("enterDate")))
		{
			rlt.put("enterDate", String.format("%1$ty-%1$tm-%1$td", System.currentTimeMillis()));
		}
		
		if(studentService.createStudent(rlt))
		{
			//跳转到学生信息保存成功页
			//该页面需提示操作员进一步设置学生信息
			return new TraceObject(Constants.COMMON_SUCCESS_ACTION);
		}
		else
		{
			return new TraceObject(None);
		}
	}
}
